package com.gwl.circle.user.controller;

import com.gwl.circle.common.bo.UserAddBo;
import com.gwl.circle.common.bo.UserLoginBo;
import com.gwl.circle.common.config.SystemConfig;
import com.gwl.circle.common.vo.R;
import com.gwl.circle.user.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author 高万里
 */
@RestController
@RequestMapping("/server/user/")
public class UserController {

    @Resource
    private UserService service;

    @PostMapping("register")
    public R register(@RequestBody UserAddBo bo, HttpServletRequest request){
        return service.register(bo, request.getRemoteAddr());
    }

    @PostMapping("login")
    public R login(@RequestBody UserLoginBo bo, HttpServletRequest request) {
        return service.Login(bo, request.getRemoteAddr());
    }

    @GetMapping("all")
    public R all() {
        return service.all();
    }

    @GetMapping("growthRecord")
    public R growthRecord(HttpServletRequest request) {
        return service.queryByToken(request.getHeader(SystemConfig.HEADER_TOKEN));
    }

    @GetMapping("logout")
    public R logout(HttpServletRequest request){
        return service.Logout(request.getHeader(SystemConfig.HEADER_TOKEN));
    }
}
